﻿Ext.ns("Kwan");
var deskWidth, deskHeight;
Kwan = {
    // helper
    objToString: function (o) {
        var s = '{\n';
        for (var p in o)
            s += '    "<b>' + p + '</b>": "' + o[p] + '"\n';
        return s + '}';
    },
    Debug: function (o) {
        document.write(this.objToString(o));
    },
    createWindow: function (app, title, url) {
        var desk = app.getDesktop();
        var win = Ext.getCmp('win_' + title);
        if (win) {
            win.show();
            //var delayedTask = new Ext.util.DelayedTask();
            //delayedTask.delay(300, function (arg) {
            win.reload();
            //});
        } else {
            var w = desk.createWindow({
                id: 'win_' + title,
                title: title,
                width: deskWidth - 200, height: deskHeight - 80,
                maximizable: true, minimizable: true, constrain: true,
                //maximized:true,
                plain: true, layout: 'fit', closeAction: 'close',
                autoLoad: { url: url, mode: "iframe", layout: "fit", showMask: false, scripts: true, scope: this, cache: false }
            });
            //w.center();
            w.show();
        }
    },
    shortstart: function (desk, path) {
        var url = "/Ext/" + path + "/Default.aspx";
        this.createWindow(desk, path, url);
    },
    alignPanels: function () {
        deskWidth = Ext.getBody().getWidth();
        deskHeight = Ext.getBody().getHeight();
        pnlSample.getEl().alignTo(Ext.getBody(), "tr", [-505, 5], false);
    },
    fmDT: function (d) {
        if (d == null) { return d; }
        var reg = /([^\b]+)\./g;
        reg.exec(d);
        return RegExp.$1.replace('T', ' ');
    }
};